
<h1>Simple example</h1>

<p>Before trying the example make sure you have follow <a href="../installation/index.html">installation</a> instruction first.</p>

<p>Using DX Auth library it's pretty straight forward and simple,
for example let's create a class named Auth in Auth controller.</p>

<pre class="brush: php">
class Auth extends Controller
{
	function Auth()
	{
		parent::Controller();
		// Load library
		$this->load->library('DX_Auth');
	}
	
	function login()
	{
		// Login using username 'test' and password 'helloworld'
		$this->dx_auth->login('test', 'helloworld');
	}
	
	function logout()
	{
		// Logout user
		$this->dx_auth->logout();
	}
	
	function register()
	{
		// Register a user with username 'john', password 'johnpassword', and email 'john@yourmail.com'
		if ($user = $this->dx_auth->register('john', 'johnpassword', 'john@yourmail.com'))
		{
			echo 'Welcome '.$user->username;
		}
		else
		{
			echo 'Failed to register';
		}
	}
	
	function hello()
	{
		// Check if user is logged in or not
		if ($this->dx_auth->is_logged_in())
		{
			echo 'Hello world';
		}
		else
		{
			echo 'Not logged in';
		}
	}
}

</pre>

<p>By just looking these example, i think you already get a grip how easy and simple to use DX Auth library.<br/>
If you are interested, here is the more <a href="advanced.html">advanced example</a>.
</p>